package com.twu.biblioteca;

class ReserveController extends AbstractController {

    private BookManager bookManager;

    private Controller next;

    void setBookManager(BookManager bookManager) {
        this.bookManager = bookManager;
    }

    void setNext(Controller controller) {
        this.next = controller;
    }

    @Override
    public void enter() {
        getUserInterface().prompt("Please insert book title:");
    }

    @Override
    public Controller handle(String input) {
        Book book = new Book(input);
        return reserve(book);
    }

    Controller reserve(Book book) {
        boolean reservationIsSuccessful = bookManager.reserveBook(book);
        if (reservationIsSuccessful) {
            getUserInterface().showReservationSucceededMessage();
        } else {
            getUserInterface().showReservationFailedMessage();
        }
        return next;
    }

}
